package com.chance.cc.crawler.development.command.job.domain;

import com.chance.cc.crawler.development.command.job.CrawlerJobCommand;
import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.CrawlerJob;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.meta.core.bean.CrawlerMetaConstant;

/**
 * created by CC on 2020/11/26
 * mail 279020185@qq.com
 */
public class CN21CrawlerScheduleJob {

    public static void main(String[] args) {
        String domain = "21cn";

        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl("http://news.21cn.com/domestic/")
                .recordKey("http://news.21cn.com/domestic/")
                .releaseTime(System.currentTimeMillis())
                .filter(CrawlerEnum.CrawlerRecordFilter.keyOrDateRange)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*50,null))
                .build();

        CrawlerJob cn21CronRealTime = cn21CronRealTime(domain,requestRecord);

        CrawlerJobCommand crawlerJobCommand = new CrawlerJobCommand("localhost",9599);

        //21cn实时定时采集
//        HttpPage page = crawlerJobCommand.addOrUpdateCrawlerScheduleJob(domain,cn21CronRealTime,"21cn实时定时采集");
    }

    /**
     * 21cn实时定时采集
     * @param domain
     * @param requestRecord
     * @return
     */
    public static CrawlerJob cn21CronRealTime(String domain,CrawlerRequestRecord requestRecord){
        return CrawlerJob.builder()
                        .triggerInfo(domain, CrawlerMetaConstant.ScheduleJobTrigger_Cron,System.currentTimeMillis(),CrawlerMetaConstant.ScheduleJobTriggerJob_Realtime)
                        .crawlerRequestQueue(CrawlerMetaConstant.memoryRequestQueue(domain))
                        .fileResultPipeline(null,"D:\\chance\\log\\tets.log",true) //文件输出
                        .requestRecord(requestRecord)
                        .build();
    }

}
